package com.cdn.allmobilestore.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;

import com.cdn.allmobilestore.model.AppInfo;
import com.cdn.allmobilestore.ui.DetailFragment;
import com.cdn.allmobilestore.ulti.Constant;
import com.cdn.allmobilestore.ulti.Log;

public class DetailActivity extends BaseActivity {
	
	String mAppId = "";
	String mAppName = "";
	String mAppAgency = "";
	String mAppCategory = "";
	Float mAppSize = 0F;
	String mIcon 	= "";
	String mPackageName = "";
	

	@Override
	protected Fragment newFragmentByTag(String tag)
	  {	 
		Log.v("FRAGMENT_TAG_DETAIL");
		Fragment mDetailFragment = null;
	    if (TextUtils.equals(tag, Constant.FRAGMENT_TAG_DETAIL))
	    {
	       mDetailFragment = new DetailFragment();
	      ((DetailFragment)mDetailFragment).setAppId(this.mAppId);
	      ((DetailFragment)mDetailFragment).setAppName(this.mAppName);
	      ((DetailFragment)mDetailFragment).setAppAgencty(this.mAppAgency);
	      ((DetailFragment)mDetailFragment).setAppIcon(this.mIcon);
	      ((DetailFragment)mDetailFragment).setAppCat(this.mAppCategory);
	      ((DetailFragment)mDetailFragment).setAppSize(this.mAppSize);
	      ((DetailFragment)mDetailFragment).setPackageName(this.mPackageName);
	  
	      
	    }
		return mDetailFragment;
	    
	  }
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();		
		this.mAppId = intent.getStringExtra(Constant.INTENT_EXTRA_APP_ID);
		this.mAppAgency = intent.getStringExtra(Constant.INTENT_EXTRA_APP_AGENCY);
		this.mAppCategory = intent.getStringExtra(Constant.INTENT_EXTRA_APP_CAT);
		this.mAppName = intent.getStringExtra(Constant.INTENT_EXTRA_APP_NAME);
		this.mAppCategory = intent.getStringExtra(Constant.INTENT_EXTRA_APP_CAT);
		this.mAppSize = intent.getFloatExtra(Constant.INTENT_EXTRA_APP_SIZE,0);
		this.mIcon = intent.getStringExtra(Constant.INTENT_EXTRA_APP_ICON);
		this.mPackageName = intent.getStringExtra(Constant.INTENT_EXTRA_APP_PAKAGENAME);
		
		if(null == savedInstanceState)
		{			
			Log.v("mPackageName:" + mPackageName);
			setBarTitle(this.mAppName);
			setHomeButtonEnable(true);
			setSearchButtonEnable(true);			
			showFragment(Constant.FRAGMENT_TAG_DETAIL, savedInstanceState, false);
		}
		
	}

	/* (non-Javadoc)
	 * @see com.cdn.allmobilestore.activity.BaseActivity#onBackPressed()
	 */
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		if(mPackageName != null)
		{
			Intent intent = new Intent(this, MainTabActivity.class);
			startActivity(intent);
			finish();
		}		
		
	}
	
	
	
	
	
	
}
